<template>
	<!-- 编辑督办 -->
	<view class="p-10">
		<!-- 一级督办 -->
		<view class="card" v-if="isShow">
			<my-forms ref="valiForm" :model="valiFormData" :label-position="'top'" :formItem="formData1"
				label-width="200rpx"></my-forms>
		</view>
		<!-- 二级督办 -->
		<view class="card" v-if="isShow1">
			<my-forms ref="valiForm" :model="valiFormData" :label-position="'top'" :formItem="formData2"
				label-width="200rpx"></my-forms>
		</view>
		<!-- 三级督办 -->
		<view class="card" v-if="isShow2">
			<my-forms ref="valiForm" :model="valiFormData" :label-position="'top'" :formItem="formData3"
				label-width="200rpx"></my-forms>
		</view>
		<u-button class="m-t-10" type="primary" shape="circle" text="保存提交" @click="submit"></u-button>
	</view>
</template>
<script setup>
	import {
		onLoad,
	} from '@dcloudio/uni-app'
	import {
		ref,
	} from 'vue'
	import {
		infoHiddenDanger,
		editSuperviseList
	} from '@/api/hidden-danger.js'

	let isShow = ref(),
		isShow1 = ref(),
		isShow2 = ref()

	// 校验表单数据
	const formData1 = [{
			label: '一级督办人',
			disabled: true,
			prop: 'oneSupervisionUserId'
		}, {
			label: '一级督办时间',
			disabled: true,
			prop: 'oneEndDate'
		}, {
			label: '一级督办意见',
			type: 'textarea',
			required: true,
			prop: 'oneMessage'
		}],
		formData2 = [{
			label: '二级督办人',
			disabled: true,
			prop: 'twoSupervisionUserId'
		}, {
			label: '二级督办时间',
			disabled: true,
			prop: 'twoEndDate'
		}, {
			label: '二级督办意见',
			type: 'textarea',
			required: true,
			prop: 'twoMessage'
		}],
		formData3 = [{
			label: '三级督办人',
			disabled: true,
			prop: 'threeSupervisionUserId'
		}, {
			label: '三级督办时间',
			disabled: true,
			prop: 'threeEndDate'
		}, {
			label: '三级督办意见',
			type: 'textarea',
			required: true,
			prop: 'threeMessage'
		}]

	const valiForm = ref(null)
	const valiFormData = ref({})
	// 保存提交
	const submit = () => {
		valiForm.value.$refs.refMyForm.validate().then(async (res) => {
			try {
				const {
					code
				} = await editSuperviseList({
					id: ids.value,
					checkPlanId: checkPlanIds.value,
					type: types.value,
					oneMessage: valiFormData.value.oneMessage,
					twoMessage: valiFormData.value.twoMessage,
					threeMessage: valiFormData.value.threeMessage
				})
				if (code == 200) {
					uni.showToast({
						title: `编辑成功`
					})
					uni.navigateBack({
						delta: 1
					})
				}
			} catch (e) {
				//TODO handle the exception
			}
		}).catch(err => {
			console.log('err', err);
		})
	}
	let ids = ref(''),
		checkPlanIds = ref(''),
		types = ref('')
	onLoad(async (e) => {
		let data = JSON.parse(e.data)
		ids.value = data.id
		checkPlanIds.value = data.checkPlanId
		types.value = data.type
		if (data.type == 3) {
			isShow.value = true
			isShow1.value = true
			isShow2.value = true
		} else {
			isShow2.value = false
			if (data.type == 2) {
				isShow.value = true
				isShow1.value = true
			} else {
				isShow1.value = false
				if (data.type == 1) {
					isShow.value = true
				}
			}
		}
		infoHiddenDanger({
			id: data.checkPlanId
		}).then(res => {
			valiFormData.value.oneSupervisionUserId = res.data.supervision.oneSupervisionUserName
			valiFormData.value.oneEndDate = res.data.supervision.oneApplyDate
			valiFormData.value.twoSupervisionUserId = res.data.supervision.twoSupervisionUserName
			valiFormData.value.twoEndDate = res.data.supervision.twoApplyDate
			valiFormData.value.threeSupervisionUserId = res.data.supervision.threeSupervisionUserName
			valiFormData.value.threeEndDate = res.data.supervision.threeApplyDate
		})

	})
</script>
<style lang="scss" scoped>
</style>